<?php

namespace app\api\controller;

use think\Controller;

class Base extends Controller {

    //初始化
    public function _initialize()
    {
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Method: *");
        header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
    }

    /**
    返回域名域名
     */
    public function getDomain($json = true){
        $info = 'http://'.$_SERVER['HTTP_HOST'];
        if($json){
            return json(['code'=>200,'msg'=>'success','data'=>$info]);
        }else{
            return $info;
        }
    }

    function return_success($data='',$code='200',$msg='请求成功')
    {
        $data=['code'=>$code,'msg'=>$msg,'data'=>$data];
        return json($data);
    }

    /**
     * 失败返回
     * @param string $code
     * @param string $msg
     * @param string $data
     * @return mixed
     */
    function return_error($data='',$code='0',$msg='暂无数据')
    {
        $data=['code'=>$code,'msg'=>$msg,'data'=>$data];
        return json($data);
    }

    /**
     * @param $cate_id 父id
     * @param $data 循坏数据
     * @param int $lev 标记
     * @return mixed
     */
        //返回数据调用
    public function datas($data){
        if($data){
            return  $this->return_success($data);
        }else{
            return  $this->return_error($data);
        }
    }

}